package net.pinnoocle.playshoppc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.pinnoocle.playcommon.response.BaseResult;
import net.pinnoocle.playdao.entity.admin.InformDetailVo;
import net.pinnoocle.playdao.entity.admin.SaveInformParams;
import net.pinnoocle.playdao.entity.group.UpdateGroup;
import net.pinnoocle.playdao.entity.shopPc.banner.SaveBannerParams;
import net.pinnoocle.playdao.entity.web.banners.BannerListPageVo;
import net.pinnoocle.playservice.service.impl.BannersServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ye
 * @Description
 * @create 2021-11-13 11:52
 */
@RestController
@RequestMapping("/banner")
@Api(tags = "横幅管理")
public class BannerController {

    @Autowired
    BannersServiceImpl bannersService;

    @GetMapping("bannerList")
    @ApiOperation("横幅图集")
    public BaseResult<List<BannerListPageVo>> bannerList(){
        return new BaseResult<List<BannerListPageVo>>().ok(bannersService.bannerList());
    }

    @PostMapping("saveBanner")
    @ApiOperation("添加banner")
    public BaseResult<String> saveBanner(@Validated @RequestBody SaveBannerParams params){
        boolean result = bannersService.saveBanner(params);
        if(result){
            return new BaseResult<String>().success("添加成功");
        }
        return new BaseResult<String>().error("添加失败");
    }

    @PostMapping("updateBanner")
    @ApiOperation("修改banner")
    public BaseResult<String> updateInform(@Validated({UpdateGroup.class}) @RequestBody SaveBannerParams params){
        boolean result = bannersService.updateBanner(params);
        if(result){
            return new BaseResult<String>().success("修改成功");
        }
        return new BaseResult<String>().error("修改失败");
    }

    @GetMapping("deleteBanner")
    @ApiOperation("删除Banner")
    public BaseResult<String> deleteBanner(@RequestParam("bannerId") String bannerId){
        boolean result = bannersService.deleteBanner(bannerId);
        if(result){
            return new BaseResult<String>().success("删除成功");
        }
        return new BaseResult<String>().error("删除失败");
    }
}
